package com.example.model.config;

import com.example.model.interceptor.LoginInterceptor;
import com.example.model.utils.JwtUtils;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web MVC配置类
 */
@AutoConfiguration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册JWT拦截器
        registry.addInterceptor(new LoginInterceptor(new JwtUtils()))
                // 拦截所有请求
                .addPathPatterns("/**")
                // 排除登录接口，允许匿名访问
                .excludePathPatterns("/user/login")
                // 静态资源也需要排除
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/error");
    }
}